<template>
    <div class="home" ref="homeRef">
        <van-nav-bar title="商铺记录表" left-text="" left-arrow @click-left="onClickLeft" :fixed="true" :placeholder="true" />
        <div class="production" ref="listRef">
            <div class="topData">
                <div class="item">
                    <span>店铺总数</span>
                    <span>{{ all }}</span>
                </div>
                <div class="item">
                    <span>今日新增</span>
                    <span>{{ today }}</span>
                </div>
                <div class="item">
                    <span>正常营业</span>
                    <span>{{ normal }}</span>
                </div>
                <div class="item">
                    <span>营业异常</span>
                    <span>{{ abnormal }}</span>
                </div>
            </div>
            <div class="list">
                <div class="item" v-for="(i, index) in list" :key="index">
                    <div class="bgColor">
                        <span class="name">店铺名称</span>
                        <span>{{ i.name }}</span>
                    </div>
                    <div class="line">
                        <span class="name">手机号码</span>
                        <span style="color: #979797;flex: 1;">{{ i.mobile }}</span>
                    </div>
                    <div class="line">
                        <span class="name">门店地址</span>
                        <span style="color: #979797;flex: 1;">{{ i.address }}</span>
                    </div>
                    <div class="line">
                        <span class="name">当前状态</span>
                        <span style="color: #2CB9A4;">{{ getStatus(i.openswitch) }}</span>
                    </div>
                </div>
                <!-- <div class="nomore">数据加载完成</div> -->
                <noData :list="list" :lastPage="last_page" :page="page" />
            </div>
        </div>
    </div>
</template>
<script setup>
import { useRouter } from 'vue-router'
import { merchantList, merchantCensus } from "@/services";
import { onMounted } from 'vue';
import { ref, watch } from 'vue';
import noData from "@/components/noData/noData.vue"
import useScroll from '@/hooks/useScroll'
const router = useRouter();
const page = ref(1)
const abnormal = ref(0)
const normal = ref(0)
const today = ref(0)
const all = ref(0)
const list = ref([])
const last_page = ref(1)
onMounted(() => {
    getCensus()//店铺统计
    getList()//店铺记录

})
const getStatus = (i) => {
    // console.log(i)
    switch (i) {
        case 1:
            return '正常营业'
            break;
        case 0:
            return '暂停营业'
            break;
    }
}
// 监听滚动到底部
const homeRef = ref()
const { isReachBottom, scrollTop } = useScroll(homeRef)
console.log(homeRef.value)
watch(isReachBottom, (newValue) => {
    if (newValue) {
        if (page.value == last_page.value) {
            return
        } else {
            page.value++
            getList()
        }
    }
})
const getCensus = async () => {
    let res = await merchantCensus()
    all.value = res.data.all
    today.value = res.data.today
    normal.value = res.data.normal
    abnormal.value = res.data.abnormal
    // console.log(res,111)
}
const getList = async () => {
    let res = await merchantList({ page: page.value })
    // list.value = res.data.data
    list.value = [...list.value, ...res.data.data]
    last_page.value = res.data.last_page
    // console.log(list.value, last_page.value)
}
const onClickLeft = () => {
    router.back();
};
</script>
<style lang="scss" scoped>
.home {
    height: 100vh;
    overflow-y: auto;
    box-sizing: border-box;
    padding-bottom: 60px;
}

.production {
    padding: 20px;

    .topData {
        border-radius: 20px;
        background: #FFF;
        box-shadow: 0px 0px 15px 0px rgba(44, 185, 164, 0.15);
        display: flex;
        align-items: center;
        justify-content: space-around;
        padding: 20px;

        .item {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;

            &:first-child {
                color: #1D1B20;
                text-align: center;
                font-family: PingFang SC;
                font-size: 14px;
                font-style: normal;
                font-weight: 400;
                line-height: normal;
            }

            span:last-child {
                margin-top: 10px;
                color: #2CB9A4;
                font-family: PingFang SC;
                font-size: 14px;
                font-style: normal;
                font-weight: 500;
                line-height: normal;
            }
        }
    }

    .list {
        display: flex;
        flex-direction: column;
        margin-top: 20px;

        .item {
            display: flex;
            flex-direction: column;
            border-radius: 8px;
            background: #FFF;
            box-shadow: 0px 0px 10px 0px rgba(8, 23, 56, 0.05);
            padding: 20px;
            margin-bottom: 10px;

            .line {
                display: flex;
                justify-content: space-between;
                padding: 10px;
                border-bottom: 1px solid rgba(217, 217, 217, 0.60);

                &:last-child,
                &:first-child {
                    border-bottom: 0;
                }

                &:first-child {}
            }

            .name {
                width: 100px;
            }

            .bgColor {
                background: linear-gradient(90deg, #218CC9 0%, #2CB9A4 100%);
                display: flex;
                justify-content: space-between;
                padding: 10px;
                border-radius: 5px 5px 0 0;
                color: #FFF;
            }
        }
    }
}
</style>